package com.wisezone.permission.web;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import com.wisezone.common.annotation.WzWebAnnotation;
import com.wisezone.common.exception.WzWebException;
import com.wisezone.common.utils.BeanUtils;
import com.wisezone.common.utils.ConstantUtils;
import com.wisezone.common.web.BaseFormController;
import com.wisezone.permission.bean.entity.WzDepartmentEntity;
import com.wisezone.permission.bean.entity.WzPersonEntity;
import com.wisezone.permission.bean.entity.WzPositionEntity;
import com.wisezone.permission.bean.form.WzPersonForm;
import com.wisezone.permission.bean.search.WzDepartmentSearch;
import com.wisezone.permission.bean.search.WzPersonSearch;
import com.wisezone.permission.bean.search.WzPositionSearch;
import com.wisezone.permission.service.WzDepartmentService;
import com.wisezone.permission.service.WzPersonService;
import com.wisezone.permission.service.WzPositionService;

/**
 * 
 *人员; InnoDB free: 24576 kB
 * 
 * @author create by create date 2010-07-29 14:44:42 update date 2010-07-29
 *         14:44:42
 * 
 */
@WzWebAnnotation(moduleName = "person")
public class WzPersonController extends
		BaseFormController<WzPersonEntity, WzPersonSearch, WzPersonForm> {

	/**
	  *
	  *
	  *
	  */
	private WzPersonService wzPersonService;
	
	private WzPositionService wzPositionService;
	
	private WzDepartmentService wzDepartmentService;
	
	private List<WzPositionEntity> positionList;
	
	private List<WzDepartmentEntity> departmentList;
	
	

	/**
	 * 返回清空条件列表
	 * 
	 * @return
	 * @throws WzWebException
	 */
	public String toList() throws WzWebException {

		searchEntity = new WzPersonSearch();
		pagination = this.wzPersonService.listFormByPage(searchEntity);
		return LIST;
	}

	/**
	 * 获得列表
	 * 
	 * @return
	 * @throws Exception
	 */
	public String list() throws WzWebException {

		searchEntity = getSearchEntity();
		pagination = this.wzPersonService.listFormByPage(searchEntity);
		return LIST;
	}

	/**
	 * 进入新增
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterNew() throws WzWebException {

		if (id != null) {
			entity = this.wzPersonService.findById(id);
			entity.setId(null);
		}
		return NEW_EDIT;
	}

	/**
	 * 进入修改
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterEdit() throws WzWebException {

		form = this.wzPersonService.findFormById(id);
		return NEW_EDIT;
	}

	/**
	 * 进入查看
	 * 
	 * @return
	 * @throws Exception
	 */
	public String enterView() throws WzWebException {

		form = this.wzPersonService.findFormById(id);
		return VIEW;
	}

	/**
	 * 保存
	 * 
	 * @return
	 * @throws Exception
	 */
	public String save() throws WzWebException {

		entity = getEntity();
		entity.setState(ConstantUtils.STATE_EXIST);
		this.wzPersonService.save(entity);
		return toList();
	}

	/**
	 * 修改
	 * 
	 * @return
	 * @throws Exception
	 */
	public String update() throws WzWebException {

		entity = getEntity();
		WzPersonEntity oldEntity = this.wzPersonService.findById(id);
		BeanUtils.copyBean(oldEntity, entity);
		this.wzPersonService.update(oldEntity);
		return toList();
	}

	/**
	 * 删除
	 * 
	 * @return
	 * @throws Exception
	 */
	public String delete() throws WzWebException {

		Collection<Serializable> idList = getIdList();
		if (idList != null) {
			this.wzPersonService.deleteAll(idList);
		}
		return toList();
	}

	public void setWzPersonService(WzPersonService wzPersonService) {
		this.wzPersonService = wzPersonService;
	}
	

	public void setWzPositionService(WzPositionService wzPositionService) {
		this.wzPositionService = wzPositionService;
	}

	public void setWzDepartmentService(WzDepartmentService wzDepartmentService) {
		this.wzDepartmentService = wzDepartmentService;
	}

	public List<WzPositionEntity> getPositionList() {
		
		positionList = wzPositionService.listAll(new WzPositionSearch());
		return positionList;
	}

	public List<WzDepartmentEntity> getDepartmentList() {
		
		departmentList = wzDepartmentService.listAll(new WzDepartmentSearch());
		return departmentList;
	}
	
	

}